import { Fragment } from 'react'
import { Button, Col, Form, Row, Select } from 'antd';

const curriculumType = [
  { value: "1", label: "公共课/必修课" },
  { value: "2", label: "公共课/选修课" },
]

export default function CurriculumsSearch({
  onFinish,
  setAddOpen,
  additionalInfor,
  Reset
}) {
  const [form] = Form.useForm();

  const colList = [
    { colSpan: 5, span: 8, offset: 0, name: "fd_idNum", label: "任课老师", options: additionalInfor.teacher, },
    { colSpan: 4, span: 6, offset: 0, name: "fd_claNum", label: "班级", options: additionalInfor.classes, },
    { colSpan: 5, span: 8, offset: 0, name: "fd_type", label: "课程类别", options: curriculumType, },
    { colSpan: 5, span: 6, offset: 0, name: "fd_professionalNum", label: "专业", options: additionalInfor.professionals, },
  ]

  return (
    <Fragment>
      <Form
        form={form}
        name="advanced_search"
        onFinish={onFinish}
        size="small"
      >
        <Row gutter={32} >
          {
            colList.map((item) => {
              return (
                <Col span={item.colSpan} style={{ padding: "0px 0px 0px 10px" }} key={item.name}>
                  <Form.Item
                    key={item.name}
                    name={item.name}
                    label={item.label}
                    rules={[item.rules]}
                    labelAlign="left"
                    labelCol={{ span: item.span }}
                    wrapperCol={{ span: 15 }}
                  >
                    <Select
                      showSearch
                      filterOption={(input, option) =>
                        (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
                      }
                      key="value"
                      options={item.options}
                    />
                  </Form.Item>
                </Col>
              )
            })
          }
          <Form.Item>
            <Button htmlType="submit">搜索</Button>
            <Button onClick={() => {
              form.resetFields()
              Reset()
            }}>重置</Button>
          </Form.Item>
          <Form.Item>
            <Button onClick={() => { setAddOpen(true) }}>添加新课程</Button>
          </Form.Item>
        </Row>
      </Form>
    </Fragment>
  )
}
